package com.example.server.web.controller;


import com.example.server.web.domain.RespBean;
import com.example.server.web.domain.dto.*;
import com.example.server.web.domain.page.PageQueryDto;
import com.example.server.web.service.StudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  学生接口 前端控制器
 * </p>
 *
 * @author 作者
 * @since 2023-04-04
 */
@RestController
@RequestMapping("/student")
@Api(tags = {"学生接口"})
public class StudentController {

    @Autowired
    private StudentService studentService;

    @ApiOperation("添加学生")
    @PostMapping("/addStudent")
    public RespBean addTeacher(@RequestBody StudentAddDto studentAddDto){
        studentService.addStudentAndUser(studentAddDto);
        return RespBean.success("添加成功");
    }

    @ApiOperation("查看学生分页数据")
    @GetMapping("/page")
    public RespBean addTeacher(PageQueryDto pageQueryDto, StudentParamDto studentParamDto){
        Map map = studentService.getPage(pageQueryDto,studentParamDto);
        return RespBean.success("查询成功",map);
    }

    @ApiOperation("修改学生")
    @PostMapping("/updateStudent")
    public RespBean updateStudent(@RequestBody StudentAddDto studentAddDto){
        studentService.updateStudent(studentAddDto);
        return RespBean.success("修改成功");
    }

    @ApiOperation("删除学生")
    @PostMapping("/deleteStudent")
    public RespBean deleteStudent(@RequestBody List<Long> ids){
        studentService.deleteStudent(ids);
        return RespBean.success("删除成功");
    }

    @ApiOperation("查看学生详情信息")
    @GetMapping("/selectDetail/{id}")
    public RespBean selectDetail(@PathVariable("id") Long id){
        StudentAddDto studentAddDto = studentService.selectDetail(id);
        return RespBean.success("查询成功",studentAddDto);
    }

}